package com.aqie.easy.string;

import com.aqie.easy.utils.StringUtil;


/**
 * 557. 反转字符串中的单词 III
 * StringBuffer ： 安全
 */
public class ReverseWords {
    public String reverseWords(String s) {

        String[] strings = s.split("\\s+");
        for (int i = 0; i < strings.length; i++){
            strings[i] = new StringBuilder(strings[i]).reverse().toString();
        }
        return String.join(" ", strings);
    }

    public static void main(String[] args) {
        String str = "Let's take LeetCode contest";
        // java 字符串转 数组
        String[] strings = str.split("\\s+");
        StringUtil.printString(strings);

        // java 数组转字符串
        String res = String.join("," ,strings);
        System.out.println(res);

        // 翻转一个字符串
        String aqie = "aqie";
        String reverseAqie = new StringBuilder(aqie).reverse().toString();
        System.out.println(reverseAqie);
    }
}
